package com.youngjun.generator;

import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.Timestamp;

/**
 * <p>
 * ORACLE 字段类型转换
 * </p>
 *
 * @author hubin
 * @since 2017-01-20
 */
public class JavaFieldTypeConverter {

    public static JavaFieldType parse(String columnType, int columnSize, int decimalDdigits) {
        String t = columnType.toLowerCase();
        if (t.contains("char")||t.contains("text")) {
            return new com.youngjun.generator.JavaFieldType("VARCHAR", String.class.getName());
        } else if (t.contains("date")) {
            return new JavaFieldType("DATE", Date.class.getName());
        } else if (t.contains("timestamp")) {
            return new JavaFieldType("TIMESTAMP", Timestamp.class.getName());
        } else if (t.contains("int8") || t.contains("bigint")) {
            return new JavaFieldType("BIGINT", Long.class.getName());
        }else if (t.contains("int2") || t.contains("int4")) {
            return new JavaFieldType("INTEGER", Integer.class.getName());
        } else if (t.contains("bit") || t.contains("bool") || t.contains("tinyint")) {
            return new JavaFieldType("BOOLEAN", Boolean.class.getName());
        }else if (t.contains("float4")) {
            return new JavaFieldType("FLOAT", Float.class.getName());
        } if (t.contains("float8") || t.contains("double")) {
            return new JavaFieldType("DOUBLE", Double.class.getName());
        }else if (t.contains("clob")) {
            return new JavaFieldType("CLOB", Clob.class.getName());
        } else if (t.contains("blob")) {
            return new JavaFieldType("BLOB", Blob.class.getName());
        } else if (t.contains("binary")) {
            return new JavaFieldType("BINARY", Blob.class.getName());
        }else if (t.contains("numeric")) {
            return new JavaFieldType("NUMERIC", Blob.class.getName());
        } else {
            return new JavaFieldType("VARCHAR", String.class.getName());
        }
    }


}
